Then(/^I should receive an email message containing an activation link$/) do
  mail = Mail::TestMailer.deliveries.shift
  expect(mail).not_to be_nil
  expect(mail.to[0]).to eq registration_params[:user][:email]
  expect(mail.html_part).not_to be_nil
  expect(mail.text_part).not_to be_nil
  expect(mail.text_part.to_s).to match(%r{/registration/confirm})
  html = Nokogiri.parse mail.html_part.to_s
  @link = html.css('a').first.attr('href')
  expect(@link).to match(%r{/registration/confirm})
end

Given(/^there is a guy who is registered with the email address '(.+)'$/) do |email|
  create(:user, email: email)
end

Then(/^I should be informed with the email collision$/) do
  expect(@response['ok']).to be_falsey
  expect(@response['errors']['email']).to include('has already been taken')
end

When(/^I follow that link$/) do
  url = URI(@link)
  get url.path, query: url.query do |response, status|
    @response, @status = response, status
  end
end

Then(/^my account should be activated$/) do
  p @response
  expect(@response['user']['activated_at']).not_to be_nil
  # expect(User.where(email: 'foo@bar.com').first).to be_activated
end